from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from django.urls import reverse

from myapp2.models import Author

def index(request):
    # 3.在子路由的views中反向解析URL地址：reverse('命名空间:视图名称',args参数)
    url=reverse("myapp2:index1")
    # url=reverse("index1")
    # return  HttpResponse("myapp2的index页面", url)
    return  render(request,'index.html',{'url':url})

def getBooks(request):
    # 使⽤related_name访问反向关系
    author = Author.objects.get(name='张三')

    books = author.books.all()  # ⽽不是author.book_set.all()
    return  render(request,'books.html',{'books':books})



